/*
* 系统有关访问接口数据
*/
import { setCommonSystemLoading, setCommonDate } from './Action';
import * as DataName from './DataNameConfig';
import { SYSTEM_API_TYPE } from "../utils/Api";
import Util from '../utils/Util';
import HttpServer from '../axios';

/**
 * 通知列表
 * @param {Object} filter
 */
export const GetNotifyList =(filter)=> {
    return dispatch=>{
        HttpServer(Util.getApi(SYSTEM_API_TYPE,"NotifyList"),filter)
            .then((res)=>{
                dispatch(setCommonSystemLoading(DataName.BASE_CARD_LOADING,false));
                dispatch(setCommonSystemLoading(DataName.BASE_TABLE_LOADING,false));
                res.result.filter = filter;
                dispatch(setCommonDate('set_base_data',DataName.NOTIFY_LIST,res.result))
            },(error)=>{
                dispatch(setCommonSystemLoading(DataName.BASE_TABLE_LOADING,false));
                console.log(error)
            })
    }
}

/**
 * 删除消息通知
 * @param {Object} filter
 */
export const DeleteNotify =(filter,content)=> {
    return dispatch=>{
        HttpServer(Util.getApi(SYSTEM_API_TYPE,"DeleteNotify"),filter)
            .then((res)=>{
                let ind = -1;
                content.forEach((d,index)=>{
                    if(d.id === filter.id){
                        ind = index;
                    }
                })
                content.splice(ind,1);
                dispatch(setCommonSystemLoading(DataName.BASE_TABLE_LOADING,false));
            },(error)=>{
                dispatch(setCommonSystemLoading(DataName.BASE_TABLE_LOADING,false));
                console.log(error)
            })
    }
}

